//
//  ST_MemberAlertViewController.swift
//  btvideo
//
//  Created by mac on 2020/5/13.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift


//MARK: -
class ST_MemberAlertViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(root_view)
        root_view.snp.makeConstraints { (make) in
            make.width.equalTo(root_view_width)
            make.height.equalTo(root_view_height)
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
//            .offset(-ScreenHeight/10)
        }
        
        root_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.height.equalTo(139)
            make.left.right.top.equalToSuperview()
        }
        
        root_view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(cover_image_view.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(23)
            make.right.equalToSuperview().offset(-23)
        }
        
        root_view.addSubview(confirm_btn)
        
        root_view.addSubview(cancel_btn)
        
        cancel_btn.backgroundColor = UIColor.clear
        
        
        confirm_btn.snp.remakeConstraints { (make) in
            make.bottom.equalTo(cancel_btn.snp.top).offset(-4)
            make.width.equalTo(200)
            make.height.equalTo(44)
            make.centerX.equalToSuperview()
        }
        
        cancel_btn.snp.remakeConstraints { (make) in
            make.bottom.equalToSuperview().offset(-4)
            make.width.height.equalTo(confirm_btn)
            make.centerX.equalToSuperview()
        }
        
        cancel_btn.setTitleForAllStates(cancel_btn_title)
    }
    
    fileprivate func hidden_cancel_btn_with_layout(){
        
        
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
   @objc public convenience init(message:String,imageName:String,confirmText:String,cancelText:String) {
    
        self.init(nibName: nil, bundle: nil)
        
        cover_image_view.image = UIImage.init(named: imageName)
    
        let attrString = NSMutableAttributedString(string: message)
        
        let paragh = NSMutableParagraphStyle()
    
        paragh.lineSpacing = 5
    
        paragh.alignment = .center
        
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 0.38, green: 0.4, blue: 0.44, alpha: 1),.paragraphStyle:paragh]
    
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        titleLabel.attributedText = attrString
        
        cancel_btn_title = cancelText
         
        confirm_btn.setTitleForAllStates(confirmText)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK:- Properties
   @objc var root_view_height = 320.cgFloat
    
    @objc var root_view_width = 300.cgFloat
    
    fileprivate lazy var root_view:UIView = {
       let control = UIView()
        control.backgroundColor = Color.white
        control.cornerRadius = 20
        control.borderColor = Color.init(hexString: "#979797")
        control.borderWidth = 1
        return control
    }()
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        return control
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 0
        control.textAlignment = .center
        return control
    }()
    
    /*
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 0
        return control
    }()
    */

    fileprivate lazy var confirm_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = Color.init(hexString: "#FEC207")
        control.cornerRadius = 22
        control.setTitleForAllStates("知道了")
        control.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.semibold)
        control.setTitleColorForAllStates(UIColor.white)
        control.addTarget(self, action: #selector(confirm_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate var cancel_btn_title = "重新选择"
    
    fileprivate lazy var cancel_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = Color.init(hexString: "#F2F4F7")
        control.cornerRadius = 22
        control.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.regular)
        control.setTitleColorForAllStates(UIColor.init(hexString: "#61666F")!)
        control.addTarget(self, action: #selector(cancel_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    
//    MARK: - Public
    
    @objc var confirm_closure:(()->())?
    @objc var cancel_closure:(()->())?
    
}


extension ST_MemberAlertViewController{
    
    @objc func confirm_handle(){
        
        
        
        self.dismiss(animated: false) {
            self.confirm_closure?()
        }
        
    }
    
    @objc func cancel_handle(){
        
        self.dismiss(animated: false) {
            self.cancel_closure?()
        }
    }
    
}
